package com.ashen.study.service.impl;

import com.ashen.study.entity.UserInfo;
import com.ashen.study.mapper.UserInfoMapper;
import com.ashen.study.model.request.UserRequest;
import com.ashen.study.aop.AdminOnly;
import com.ashen.study.service.UserInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huangxiaolin
 * @version 1.0.0
 * @ClassName UserInfoServiceImpl.java
 * @Description
 * @createTime 2019年05月06日 15:34:00
 */
@Service
//@NeedSecured
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;


    @Override
    public List<UserInfo> getUserInfo() {
        return userInfoMapper.getuserinfolist();
    }


    @Override
    public boolean insert(UserRequest request) {
        UserInfo userInfo =UserInfo.addOf(request);
        return userInfoMapper.insertSelective(userInfo) > 0;
    }


    @Override
    public boolean update(UserRequest userRequest)  {
        UserInfo userInfo = UserInfo.updateOf(userRequest);
        return userInfoMapper.updateByPrimaryKey(userInfo) > 0;
    }

    /**
     * 根据id删除信息
     *
     * @param id
     * @return
     */
    @Override
//    @AdminOnly
    public boolean delete(Integer id) {
        return userInfoMapper.deleteByPrimaryKey(id) > 0;
    }
}
